package com.ddw.wotcg.client.utils;

import com.google.gwt.dom.client.Document;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;

/**
 * Represents a utility class to route enter key presses to a click handler
 * 
 * @author fungus1487
 * @deprecated unused so far
 * 
 */
@Deprecated
public class RouteEnterKey implements KeyPressHandler {
	
	private final HasClickHandlers routeTo;
	
	/**
	 * Creates a new route enter key instance
	 * 
	 * @param input
	 *            the input to monitor enter key presses for
	 * @param routeTo
	 *            the element to route the click event to on enter
	 */
	public RouteEnterKey(HasKeyPressHandlers input, HasClickHandlers routeTo) {
		this.routeTo = routeTo;
		input.addKeyPressHandler(this);
	}
	
	@Override
	public void onKeyPress(KeyPressEvent event) {
		if (event.isAnyModifierKeyDown() == false
				&& event.getCharCode() == KeyCodes.KEY_ENTER) {
			ClickEvent.fireNativeEvent(
					Document.get().createClickEvent(-1, -1, -1, -1, -1, false,
							false, false, false), this.routeTo);
		}
	}
	
}
